/*
 *  hihocoder.com
 *
 *  Category: Enumerate and Binary Search
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int N, K;
int A[200002];

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    cin >> N >> K;

    for (int i = 0; i < K; ++i) cin >> A[i];

    sort(A, A + K);

    for (int i = 0; i < K; ++i) A[i + K] = A[i] + N;

    int half = (N - 1) / 2;

    long count = 0;

    // special case 1
    if (K < 3) {
        cout << 0 << endl;
        return 0;
    }

    // special case 2
    if (A[K - 1] - A[0] < half) {
        cout << (long)K * (K - 1) * (K - 2) / 6 << endl;
        return 0;
    }

    for (int i = 0; i < K; ++i) {
        int *b = upper_bound(A + i, A + i + K, A[i] + half);

        long n = b - A - i;

        if (n > 2) count += (n - 1) * (n - 2) / 2;
    }

    cout << count << endl;

    return 0;
}

/*-------- Functions --------*/

